#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX = 0x3f3f3f3f;
int T, N, M;
int dp[3009][3009];
int len[3009];
inline int abs(int x)
{
	return x > 0 ? x : -x;
}
int main()
{
	scanf("%d", &T);
	for (int TT = 1; TT <= T; TT++)
	{
		scanf("%d%d", &N, &M);
		for (int i = 1; i <= N; i++)
			scanf("%d", &len[i]);
		memset(dp, 0x3f, sizeof(dp));
		for (int i = 0; i <= M; i++)
			dp[0][i] = 0;
		int ans = MAX;
		for (int i = 0; i < N; i++)
			for (int j = 0; j <= M; j++)
				if (dp[i][j] < MAX)
				{
					int sum = -1;
					for (int k = i + 1;k <= N; k++)
					{
						sum += 1 + len[k];
						if (sum > M)
							break;
						dp[k][sum] = min(dp[k][sum], dp[i][j] + abs(sum - j));
						if (k == N)
							ans = min (ans, dp[k][sum]);
					}
				}
		// for (int i = 0; i <= N; i++)
		// {
		// 	for (int j = 0; j <= M; j++)
		// 		printf("% 4d",dp[i][j] < MAX ? dp[i][j] : -1 );
		// 	printf("\n");
		// }
		printf("Case #%d: %d\n", TT, ans);
	}
	return 0;
}
